package main
import "fmt"
import "sync"

var wg sync.WaitGroup


func main() {
	
	for i := 1; i < 10; i++ {
		wg.Add(1)//启动一个goroutine就添加一个协程
		// go factorialSum(i)
		go testEveryOne (i)
	}
	wg.Wait()

	// lock.Lock()
	// for i,v := range myMap {
	// 	fmt.Printf("map[%d]=%d\n",i,v)
	// }
	
/*
	var(
		c = 90
		//d = "hello",这里如果定义参数d,在下面👇🏻函数打印
	)
		// fmt.Println("c:" + c )
		fmt.Println("c:" + fmt.Sprint(c))
		//fmt.Sprint(num)
*/
}

var(
	c = 90
	d = "hello"
)

var (
	myMap = make(map[int]int ,200)
	//lock是一个全局的互斥锁；sync是一个包：synchornized 同步
	//
	lock sync.Mutex
)

func testEveryOne(n int){
	fmt.Println("testEveryOne:",n)
	defer wg.Done()
}


func factorialSum(n int){
    res := 1
	for i := 1; i < n; i++ {
		res *= i 
	}
	lock.Lock()
	myMap[n] = res
	lock.Unlock()
}



